package 力扣日常刷题.木22二月.第17天223;

import 力扣日常刷题.ListNode;

import java.util.LinkedList;

/**
 * @author 帅小伙
 * @date 2022/2/23
 * @description
 */
public class Demo150反转链表 {


    public ListNode reverseList(ListNode head) {
        if(head == null || head.next == null) return head;
        ListNode nHead = reverseList(head.next);
        head.next.next = head;
        head.next = null;
        return nHead;
    }


    public ListNode reverseList2(ListNode head) {
        if(head == null || head.next == null) return head;

        ListNode pre = null;
        ListNode curr = head;

        while (curr!= null) {
            ListNode next = curr.next;
            curr.next = pre;
            pre = curr;
            curr = next;
        }
        return pre;

    }




}
